// var parameter = getRequest();
// var username = parameter['username'];//参数名
// var userID = parameter['userID'];//参数名
// var openid = parameter['openid'];//参数
var initialopen=1; //初始化  表示第一次打开页面  第一次打开页面时 window窗口还没加载完毕，onSelect()事件直接调用 窗口会报错
var userdepartment;  // 员工对应的部门
var employee_Data;  // 员工所有数据

var currentyears; // 维修保养 页当选选择的年份


$(function () {
   // 请购数据
   //  getpurchase();  //获取请购30天内的明细数据
   //  getpurchaseImg();  // usp_getpurchaseBillontime

    // 保养数据
    // getmaint_sum();
    // getmaintImg();
    // ceshi01()
    // cratertable([{sid:'1',name:'kli'}],'reportContainer02')

   setInterval(getSelectedGrid, 60000);

    setcom()

});

function initChannel(val){
    const channel = new BroadcastChannel('cc');
    channel.postMessage(val);
}

function getSelectedIndex() {
    let tab = $('#tabs').tabs('getSelected');
    let index = $('#tabs').tabs('getTabIndex', tab);
    return index;
}

function getSelectedIndex01() {
    let tab = $('#tabs01').tabs('getSelected');
    let index = $('#tabs01').tabs('getTabIndex', tab);
    return index;
}

function getSelectedGrid() {
    // switch (getSelectedIndex()) {
    //     case 0:
    //         kendoGridID = '#bill';
    //         break;
    //     case 1:
    //         kendoGridID = '#bill_zf';
    //         break;
    // }
    onSelect('',getSelectedIndex())
}


function onSelect(title, index) {
    switch (index) {
        case 0:
            if (initialopen===1){
                setPrioritiesGrid();
                setPrioritiesGrid01();
                setPrioritiesGridAll();
                setTimeout(function() { Priorities_Refresh();},1000);
                initialopen=0;
            }else{
                Priorities_Refresh()
            }
            break;
        case 1:
            getpurchase();  //获取请购30天内的明细数据
            getpurchaseImg();  // usp_getpurchaseBillontime
            break;
        case 2:
            getmaint_sum();

            let slideButton05 = document.querySelector('.slide-button05');
            let left05 = slideButton05.querySelector('.left05');
            let right05 = slideButton05.querySelector('.right05');
            left05.style.background='aquamarine';
            right05.style.background='#C0C0C0';

            getmaintImg(THISYEAR);
            // ceshi01();

            getrepair_main_sum();
            getrepairImg(THISYEAR);
            currentyears=THISYEAR;
            break;
        case 3:
            getleave_sum();

            let slideButton01 = document.querySelector('.slide-button01');
            let left01 = slideButton01.querySelector('.left01');
            let right01 = slideButton01.querySelector('.right01');
            left01.style.background='aquamarine';
            right01.style.background='#C0C0C0';

            let slideButton02 = document.querySelector('.slide-button02');
            let left02 = slideButton02.querySelector('.left02');
            let right02 = slideButton02.querySelector('.right02');
            left02.style.background='aquamarine';
            right02.style.background='#C0C0C0';

            getleaveImg('月');
            getleaveImg_hour('月');
            break;
        case 4:
            getovertime_sum();

            let slideButton03 = document.querySelector('.slide-button03');
            let left03 = slideButton03.querySelector('.left03');
            let right03 = slideButton03.querySelector('.right03');
            left03.style.background='aquamarine';
            right03.style.background='#C0C0C0';

            var slideButton04 = document.querySelector('.slide-button04');
            var left04 = slideButton04.querySelector('.left04');
            var right04 = slideButton04.querySelector('.right04');
            left04.style.background='aquamarine';
            right04.style.background='#C0C0C0';

            getovertimeImg('月');
            getovertimeImg_hour('月');

            break;

        case 5:
            getinspect_sum();

            // getiQC_sum();
            getinspectImg();
            // getQCImg_TOP5();
            break;
        case 6:
            getquality_zl();
            getQC_zl();
            break;
        case 7:
            getquality_sum();
            break;

        case 8:
            linestate();
            break;

    }

}

function onSelect01(title, index) {
    switch (index) {
        case 0:
            Priorities_Refresh();
            break;
        case 1:
            Priorities_Refresh();
            break;
        case 2:
            Priorities_Refresh();
            break;
    }

}

/**
 * purchase
 * 请购任务 数据
 */

function getpurchase() {
    $.ajax({
        url: strLin + "customSqlAccount/callProc",
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(['usp_getpurchase30daydetail']),
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            let data=cdata.data;
            // //console.log(data);
            treatsh_number(data)
        }
    });

}

//待审核数量
function treatsh_number(data) {
    let audit_department=0,audit_factory=0,audit_vp=0,audit_manager=0,audit_material=0,daydiff=0,FactLL=0,finished=0,unfinish=0,audit=0,unaudit=0;
    for (let i=0;i<data.length;i++){
        // data[i].audit_manager=1 表示总经理已审核，总经理审核过代表所有人已审核
        audit_department +=data[i].audit_manager>0?0:data[i].audit_department>0?0:1;
        audit_factory += data[i].audit_manager>0?0:data[i].audit_factory>0?0:1;
        audit_vp += data[i].audit_manager>0?0:data[i].audit_vp>0?0:1;
        audit_manager += data[i].audit_manager>0?0:data[i].audit_manager>0?0:1;
        audit_material += data[i].audit_manager>0?0:data[i].audit_material>0?0:1;
        daydiff += data[i].daydiff<0?1:0;
        if (data[i].qtydfact>0 && data[i].qtydfact === data[i].qtykc){
            FactLL +=1;
        }

        if (data[i].qtydfact>0 && data[i].qtykc<=0){
            finished +=1;
        }
        // finished += data[i].progress=='已到货'?1:0;

        unfinish += data[i].progress=='已下单'?1:0;
        // if (data[i].audit_department>0 && data[i].audit_factory>0 && data[i].audit_vp>0 && data[i].audit_manager>0 && data[i].audit_material>0){
        //     audit +=1;
        // }else{
        //     unaudit +=1;
        // }

        if (data[i].progress != '待审核' && !(data[i].qtydfact >0 && data[i].qtykc <=0)){
            audit +=1;
        }

        if (data[i].progress === '待审核' && data[i].audit_department != 2 && data[i].audit_factory !=2 && data[i].audit_vp !=2 && data[i].audit_manager !=2 && data[i].audit_material !=2){
            unaudit +=1;
        }



    }
    //item.qtydFact > 0 && item.qtydFact==item.qtykc

    $('#treatsh1').text('部门主管：'+ audit_department);
    $('#treatsh2').text('工 场 长 ：'+ audit_factory);
    $('#treatsh3').text('副总经理：'+ audit_vp);
    $('#treatsh4').text('总 经 理 ：'+ audit_manager);
    $('#treatsh5').text('资 材 课 ：'+ audit_material);
    // $('#treatsh6').text('逾期未到货:'+ daydiff);
    // $('#treatsh7').text('到货未领用:'+ FactLL);

    $('#treatsh11').text('总笔数：'+ data.length);
    $('#treatsh12').text('已完成：'+ finished);
    $('#treatsh13').text('待审核：'+ unaudit);
    $('#treatsh14').text('已审核：'+ audit);
    $('#treatsh15').text('已下单：'+ unfinish);
    $('#treatsh16').text('逾期未到货:'+ daydiff);
    $('#treatsh17').text('到货未领用:'+ FactLL);
}

function getpurchaseImg() {
    $.ajax({
        url: strLin + "customSqlAccount/callProc",
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(['usp_getpurchaseBillontime']),
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            let data=cdata.data;
            //console.log(data);
            setpurchaseImgdata(data)
        }
    });

}

//转换图形数据的格式
function setpurchaseImgdata(vdata) {
    var dataNew=[];
    var yearData=['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
    let sumBillcode=0,ontimeBillcode=0;

    for (let index=0;index<yearData.length;index++){
        //根据 月份 名称过滤出对应的所有数据
        let jsonArrayNew = vdata.filter(function(item) {
            return item.billDate === yearData[index]
        });
        if (jsonArrayNew.length>0){
            // dataNew.push(1)
            sumBillcode+=jsonArrayNew[0].sumBillcode;
            ontimeBillcode+=jsonArrayNew[0].ontimeBillcode;

            let zl=(ontimeBillcode/sumBillcode)*100;
            dataNew.push(zl.toFixed(1))
        }else{
            dataNew.push(0)
        }
    }

    //console.log(dataNew)
    setHistogram01(dataNew)
}

//设置请购数据图形
function setHistogram01(vData) {
    var dom = document.getElementById('Histogram01');
    var myChart = echarts.init(dom, null, {
        renderer: 'canvas',
        useDirtyRect: false
    });
    var app = {};

    var option;

    option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow',
                label: {
                    show: true
                }
            }
        },
        grid: {
            left:50,
            bottom:25
        },
        title: {
            top:15,
            text: '请购准时到货百分比'
        },
        xAxis: {
            name: '月',
            data: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']
            // data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
        },
        yAxis: {
            type: 'value',
            axisLabel: {
                formatter: '{value}%'
            }
        },
        series: [{
            name: '准时到货百分比',
            type: 'bar',
            data: vData ,  //[5, 20, 36, 50, 90]
            tooltip: {
                valueFormatter: function (value) {
                    return value + ' %';
                }
            },
            label: {
                show: true,
                position: 'top',
                formatter: '{c}%'
            }
        }]
    };

    if (option && typeof option === 'object') {
        myChart.setOption(option);
    }

    window.addEventListener('resize', myChart.resize);
}


//根据首页链接打开请购
function openpurchase(val) {
    if (determineQX('请购单序时表', 'pview')){
        addTab('请购单序时表', 'main/html/OrderBill/purchase.html?openID='+val);
        initChannel(val)
    }else {
        $.messager.alert('提示', '当前登录账号无权限查看！');
        return;
    }
}


/**
 * purchase
 * 维修保养 数据
 */

// 保养
function getmaint_sum() {
    $.ajax({
        url: strLin + "customSqlAccount/callProc",
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(['usp_getmaint_sum']),
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            let data=cdata.data;
            // //console.log(data);
            setmaint_text(data)
        }
    });

}

//赋值文本
function setmaint_text(data) {
    let allNumber=0,finishNumber=0,UnfinishNumber=0,minute_diff=0,yq_finishNumber=0,yq_UnfinishNumber=0,zl=0,nextMonthNumber=0;
    if (data.length>0){
        allNumber=data[0].allNumber;
        finishNumber=data[0].finishNumber;
        UnfinishNumber=data[0].UnfinishNumber;
        minute_diff=data[0].minute_diff;
        yq_finishNumber=data[0].yq_finishNumber;
        yq_UnfinishNumber=data[0].yq_UnfinishNumber;
        zl=data[0].zl;
        nextMonthNumber=data[0].nextMonthNumber;

        $('#by01').text('总任务：'+ allNumber);
        $('#by02').text('已完成 ：'+ finishNumber);
        $('#by03').text('未完成：'+ UnfinishNumber);
        $('#by04').text('累计耗时 ：'+ minute_diff + '小时');

        $('#by011').text('逾期完成：'+ yq_finishNumber);
        $('#by012').text('逾期未完成：'+ yq_UnfinishNumber);
        $('#by013').text('逾期率：'+ zl + '%');
        $('#by014').text('下月任务：'+ nextMonthNumber);

    }else {

    }



}

//获取保养图形数据
function getmaintImg(val) {
    $.ajax({
        url: strLin + "customSqlAccount/callProc",
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(['usp_getmaintImg_sum',val]),
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            let data=cdata.data;
            //console.log(data);
            setmaintImgdata(data)
        }
    });

}

//转换图形数据的格式
function setmaintImgdata(vdata) {
    var dataNew01=[],dataNew02=[];
    var yearData=['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
    // var yearData=['07', '08', '09', '10', '11', '12'];

    for (let index=0;index<yearData.length;index++){
        //根据 月份 名称过滤出对应的所有数据
        let jsonArrayNew = vdata.filter(function(item) {
            return item.plan_date === yearData[index]
        });
        if (jsonArrayNew.length>0){
            dataNew01.push(Number(jsonArrayNew[0].allNumber));
            dataNew02.push(Number(jsonArrayNew[0].finishNumber));

        }else{
            dataNew01.push(0);
            dataNew02.push(0);
        }
    }

    //console.log(dataNew01);
    //console.log(dataNew02);
    setHistogram02(dataNew01,dataNew02)
}

//设置保养数据图形
function setHistogram02(vData01,vData02) {
    // var myChart = echarts.init(document.getElementById('Histogramby'));

    var dom = document.getElementById('Histogramby');
    var myChart02 = echarts.init(dom, null, {
        renderer: 'canvas',
        useDirtyRect: false
    });
    var app = {};

    var option;

    option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow',
                label: {
                    show: true
                }
            }
        },
        legend: {
            x: 'right',
            data: ['Growth', '全部', '已完成'],
            itemGap: 5
        },

        grid: {
            left:50,
            bottom:25
        },
        title: {
            top:15,
            text: '设备保养月完成数量对比图'
        },
        xAxis: {
            name: '月',
            // data: [ '7', '8', '9', '10', '11', '12']
            data: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']
            // data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
        },
        yAxis: {
            type: 'value',
            axisLabel: {
                formatter: '{value}'
            }
        },
        series: [
            {
                name: '全部',
                type: 'bar',
                data: vData01,
                label: {
                    show: true,
                    position: 'top',
                    formatter: '{c}',
                }
            },
            {
                name: '已完成',
                type: 'bar',
                data: vData02,
                label: {
                    show: true,
                    position: 'top',
                    formatter: '{c}',
                }
            }
        ]
    };

    if (option && typeof option === 'object') {
        myChart02.setOption(option);
    }

    // window.addEventListener('resize', myChart.resize);
}


// 报修维修
function getrepair_main_sum() {
    $.ajax({
        url: strLin + "customSqlAccount/callProc",
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(['usp_getrepair_main_sum']),
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            let data=cdata.data;
            // //console.log(data);
            setrepair_text(data)
        }
    });

}

//赋值文本
function setrepair_text(data) {
    var allnumber=0,tjnumber=0,jjnumber=0,ybnumber=0,finishnumber=0,Unfinishnumber=0,minute_diff=0,xy_maxdate=0,xy_mindate=0,xy_pjdate=0,wx_maxdate=0,wx_mindate=0,wx_pjdate=0;
    if (data.length>0){
        allnumber=isNull(data[0].allnumber,0);
        tjnumber=isNull(data[0].tjnumber,0);
        jjnumber=isNull(data[0].jjnumber,0);
        ybnumber=isNull(data[0].ybnumber,0);

        finishnumber=isNull(data[0].finishnumber,0);
        Unfinishnumber=isNull(data[0].Unfinishnumber,0);
        minute_diff=isNull(data[0].minute_diff,0);
        xy_maxdate=isNull(data[0].xy_maxdate,0);
        xy_mindate=isNull(data[0].xy_mindate,0);
        xy_pjdate=isNull(data[0].xy_pjdate,0);
        wx_maxdate=isNull(data[0].wx_maxdate,0);
        wx_mindate=isNull(data[0].wx_mindate,0);
        wx_pjdate=isNull(data[0].wx_pjdate,0);


        minute_diff=parseFloat(minute_diff)>60?(parseFloat(minute_diff)/60).toFixed(0) + '小时':minute_diff.toFixed(0) + '分钟'
        xy_maxdate=parseFloat(xy_maxdate)>60?(parseFloat(xy_maxdate)/60).toFixed(0) + '小时':xy_maxdate.toFixed(0) + '分钟'
        xy_mindate=parseFloat(xy_mindate)>60?(parseFloat(xy_mindate)/60).toFixed(0) + '小时':xy_mindate.toFixed(0) + '分钟'
        xy_pjdate=parseFloat(xy_pjdate)>60?(parseFloat(xy_pjdate)/60).toFixed(0) + '小时':xy_pjdate.toFixed(0) + '分钟'
        wx_maxdate=parseFloat(wx_maxdate)>60?(parseFloat(wx_maxdate)/60).toFixed(0) + '小时':wx_maxdate.toFixed(0) + '分钟'
        wx_mindate=parseFloat(wx_mindate)>60?(parseFloat(wx_mindate)/60).toFixed(0) + '小时':wx_mindate.toFixed(0) + '分钟'
        wx_pjdate=parseFloat(wx_pjdate)>60?(parseFloat(wx_pjdate)/60).toFixed(0) + '小时':wx_pjdate.toFixed(0) + '分钟'




        $('#wx01').text('报修总数：'+ allnumber);
        $('#wx02').text('特急任务：'+ tjnumber);
        $('#wx03').text('紧急任务：'+ jjnumber);
        $('#wx04').text('一般任务：'+ ybnumber);

        $('#wx011').text('已完成：'+ finishnumber);
        $('#wx012').text('未完成：'+ Unfinishnumber);
        $('#wx013').text('维修耗时：'+ minute_diff);


        $('#wx015').text('最长响应：'+ xy_maxdate);
        $('#wx016').text('最短响应：'+ xy_mindate);
        $('#wx017').text('平均响应：'+ xy_pjdate);
        $('#wx018').text('最长维修：'+ wx_maxdate);
        $('#wx019').text('最短维修：'+ wx_mindate);
        $('#wx020').text('平均维修：'+ wx_pjdate);
    }else {

    }
   //  //console.log(minute_diff);
   // //console.log( parseFloat(minute_diff)>60?1:0);


}


//获取报修图形数据
function getrepairImg(val) {
    $.ajax({
        url: strLin + "customSqlAccount/callProc",
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(['usp_getrepair_mainImg_sum',val]),
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            let data=cdata.data;
            //console.log(data);
            setrepairImgdata(data)
        }
    });

}

//转换图形数据的格式
function setrepairImgdata(vdata) {
    var dataNew01=[],dataNew02=[],dataNew03=[];
    var yearData=['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
    // var yearData=['07', '08', '09', '10', '11', '12'];

    for (let index=0;index<yearData.length;index++){
        //根据 月份 名称过滤出对应的所有数据
        let jsonArrayNew = vdata.filter(function(item) {
            return item.billdate === yearData[index]
        });
        if (jsonArrayNew.length>0){
            dataNew01.push(Number(jsonArrayNew[0].xy_maxdate.toFixed(0)));
            dataNew02.push(Number(jsonArrayNew[0].xy_mindate.toFixed(0)));
            dataNew03.push(Number(jsonArrayNew[0].xy_pjdate.toFixed(0)));

        }else{
            dataNew01.push(0);
            dataNew02.push(0);
            dataNew03.push(0);
        }
    }

    //console.log(dataNew01);
    //console.log(dataNew02);
    setHistogram03(dataNew01,dataNew02,dataNew03)
}

//设置报修数据图形
function setHistogram03(vData01,vData02,vData03) {
    // var myChart = echarts.init(document.getElementById('Histogramby'));

    var dom = document.getElementById('Histogram_wx');
    var myChart03 = echarts.init(dom, null, {
        renderer: 'canvas',
        useDirtyRect: false
    });
    var app = {};

    var option;

    option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow',
                label: {
                    show: true
                }
            }
        },
        legend: {
            x: 'right',
            data: ['最长响应时长', '最短响应时长', '平均响应时长'],
            // itemGap: 5
        },
        grid: {
            left:70,
            bottom:25
        },
        title: {
            top:15,
            text: '报修响应趋势图'
        },
        xAxis: {
            name: '月',
            data: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']
            // data: ['7', '8', '9', '10', '11', '12']
            // data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
        },
        yAxis: {
            // name: '分钟',
            type: 'value',
            axisLabel: {
                // formatter: '{value}'
                formatter: '{value}分钟'
            }
        },
        series: [
            {
                name: '最长响应时长',
                type: 'line',
                data: vData01,
                tooltip: {
                    valueFormatter: function (value) {
                        return value + ' 分钟';
                    }
                },
                label: {
                    show: true,
                    position: 'top',
                    formatter: '{c}',
                }
            },
            {
                name: '最短响应时长',
                type: 'line',
                data: vData02,
                tooltip: {
                    valueFormatter: function (value) {
                        return value + ' 分钟';
                    }
                },
                label: {
                    show: true,
                    position: 'top',
                    formatter: '{c}',
                }
            },
            {
                name: '平均响应时长',
                type: 'line',
                data: vData03,
                tooltip: {
                    valueFormatter: function (value) {
                        return value + ' 分钟';
                    }
                },
                label: {
                    show: true,
                    position: 'top',
                    formatter: '{c}',
                }
            }
        ]
    };

    if (option && typeof option === 'object') {
        myChart03.setOption(option);
    }

    myChart03.on('click', function(params) {
        if (params.seriesType === 'line') {
            // console.log(params)
            var yAxisValue = params.value; // Y轴对应的数据
            var xAxisValue = params.name; // X轴对应的数据
            var seriesName = params.seriesName; // 折线图的名称

            console.log('折线图:', seriesName);
            console.log('Y轴数据:', yAxisValue);
            console.log('X轴数据:', xAxisValue);

            if (seriesName==='最短响应时长' || seriesName==='最长响应时长'){
                let date=currentyears+'-'+add0(xAxisValue)+'-01';
                console.log(date)
                // openRepair(xAxisValue+','+yAxisValue)  // 2024年1月22日13:39:59注释掉 以前传参X轴日期，现在改传参完整的 日期
                openRepair(date+','+yAxisValue)
            }
        }
    });

}

//根据首页链接打开请购
function openRepair(val) {
    if (determineQX('设备报修记录', 'pview')){
        addTab('设备报修记录', 'main/html/OrderBill/deviceRepair.html?openID='+val);
        initChannelRepair(val)
    }else {
        $.messager.alert('提示', '当前登录账号无权限查看！');
        return;
    }
}

function initChannelRepair(val){
    const channel = new BroadcastChannel('Repair');
    channel.postMessage(val);
}


/**
 * purchase
 * 请假 数据
 */

// 请假
function getleave_sum() {
    $.ajax({
        url: strLin + "customSqlAccount/callProc",
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(['usp_getleave_main_sum']),
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            let data=cdata.data;
            // //console.log(data);
            setleave_text(data)
        }
    });

}

//赋值文本
function setleave_text(data) {
    let todaynumber=0,thisweeknumbner=0,thismonthnumbner=0,todaynumber_hour=0,thisweeknumbner_hour=0,thismonthnumbner_hour=0;
    let p_number01=0,p_number02=0,p_number03=0,p_number04=0,h_number01=0,h_number02=0,h_number03=0,h_number04=0;
    if (data.length>0){

        todaynumber=data[0].todaynumber;
        thisweeknumbner=data[0].thisweeknumbner;
        thismonthnumbner=data[0].thismonthnumbner;
        todaynumber_hour=data[0].todaynumber_hour;
        thisweeknumbner_hour=data[0].thisweeknumbner_hour;
        thismonthnumbner_hour=data[0].thismonthnumbner_hour;

        p_number01=data[0].p_number01;
        p_number02=data[0].p_number02;
        p_number03=data[0].p_number03;
        p_number04=data[0].p_number04;
        h_number01=data[0].h_number01;
        h_number02=data[0].h_number02;
        h_number03=data[0].h_number03;
        h_number04=data[0].h_number04;

        $('#qj01').text('本日：'+ todaynumber);
        $('#qj02').text('本周：'+ thisweeknumbner);
        $('#qj03').text('本月：'+ thismonthnumbner);
        $('#qj04').text('本日：'+ todaynumber_hour.toFixed(1) + '小时');
        $('#qj05').text('本周：'+ thisweeknumbner_hour.toFixed(1)+ '小时');
        $('#qj06').text('本月：'+ thismonthnumbner_hour.toFixed(1)+ '小时');

        $('#qj11').text('年休假：'+ p_number01);
        $('#qj12').text('病假：'+ p_number02);
        $('#qj13').text('事假：'+ p_number03);
        $('#qj14').text('其他：'+ p_number04);
        $('#qj15').text('年休假：'+ h_number01);
        $('#qj16').text('病假：'+ h_number02);
        $('#qj17').text('事假：'+ h_number03);
        $('#qj18').text('其他：'+ h_number04);
    }else {

    }



}


//获取报请假形数据 请假人数
function getleaveImg(val) {
    $.ajax({
        url: strLin + "customSqlAccount/callProc",
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(['usp_getleave_mainImg_sum',val]),
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            let data=cdata.data;
            //console.log(data);
            setleaveImgdata(data,val)
        }
    });

}

//转换图形数据的格式
function setleaveImgdata(vdata,val) {
    var dataNew01=[],dataNew02=[];
    // var yearData=['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
    // var monthData=['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];

    let yearData=[];

    if (val==='月'){
        for (let i=1;i<32;i++){
            yearData.push(add0(i))
        }
    }else{
        for (let i=1;i<13;i++){
            yearData.push(add0(i))
        }
    }

    for (let index=0;index<yearData.length;index++){
        //根据 月份 名称过滤出对应的所有数据
        let jsonArrayNew = vdata.filter(function(item) {
            return Number(item.start_time) === Number(yearData[index])
        });
        //console.log(jsonArrayNew)
        if (jsonArrayNew.length>0){
            dataNew01.push(Number(jsonArrayNew[0].peopleNumber.toFixed(0)));

        }else{
            dataNew01.push(0);
        }
    }

    //console.log(dataNew01);
    setHistogram04(dataNew01,yearData)
}

//设置请假人数数据图形
function setHistogram04(vData01,vData02) {
    // var myChart = echarts.init(document.getElementById('Histogramby'));

    var dom = document.getElementById('Histogram04');
    var myChart04 = echarts.init(dom, null, {
        renderer: 'canvas',
        useDirtyRect: false
    });
    var app = {};

    var option;

    option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow',
                label: {
                    show: true
                }
            }
        },
        grid: {
            left:50,
            bottom:25
        },
        title: {
            text: '月/年请假人数趋势图'
        },
        xAxis: {
            data:vData02
            // name: '月',
            // data: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']
            // data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
        },
        yAxis: {
            name: '人数',
            type: 'value',
            axisLabel: {
                formatter: '{value}'
            }
        },
        series: [
            {
                name: '请假人数',
                type: 'line',
                data: vData01,
                tooltip: {
                    valueFormatter: function (value) {
                        return value + ' 人';
                    }
                },
                label: {
                    show: true,
                    position: 'top',
                    formatter: '{c}',
                }
            },
        ]
    };

    if (option && typeof option === 'object') {
        myChart04.setOption(option);
    }

    // window.addEventListener('resize', myChart.resize);
}

//获取请假图形数据 请假时长
function getleaveImg_hour(val) {
    $.ajax({
        url: strLin + "customSqlAccount/callProc",
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(['usp_getleave_mainImg_hour_sum',val]),
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            let data=cdata.data;
            //console.log(data);
            setleaveImgdata_hour(data,val)
        }
    });

}

//转换图形数据的格式
function setleaveImgdata_hour(vdata,val) {
    var dataNew01=[],dataNew02=[];
    // var yearData=['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
    // var monthData=['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];

    let yearData=[];

    if (val==='月'){
        for (let i=1;i<32;i++){
            yearData.push(add0(i))
        }
    }else{
        for (let i=1;i<13;i++){
            yearData.push(add0(i))
        }
    }

    for (let index=0;index<yearData.length;index++){
        //根据 月份 名称过滤出对应的所有数据
        let jsonArrayNew = vdata.filter(function(item) {
            return Number(item.start_time) === Number(yearData[index])
        });
        //console.log(jsonArrayNew)
        if (jsonArrayNew.length>0){
            dataNew01.push(Number(jsonArrayNew[0].peopleNumber.toFixed(0)));

        }else{
            dataNew01.push(0);
        }
    }

    //console.log(dataNew01);
    setHistogram05_hour(dataNew01,yearData)
}

//设置请假人数数据图形
function setHistogram05_hour(vData01,vData02) {
    // var myChart = echarts.init(document.getElementById('Histogramby'));

    var dom = document.getElementById('Histogram05');
    var myChart05 = echarts.init(dom, null, {
        renderer: 'canvas',
        useDirtyRect: false
    });
    var app = {};

    var option;

    option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow',
                label: {
                    show: true
                }
            }
        },
        grid: {
            left:50,
            bottom:25
        },
        title: {
            text: '月/年请假时长趋势图'
        },
        xAxis: {
            data:vData02
            // name: '月',
            // data: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']
            // data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
        },
        yAxis: {
            name: '小时',
            type: 'value',
            axisLabel: {
                formatter: '{value}'
            }
        },
        series: [
            {
                name: '请假时长',
                type: 'line',
                data: vData01,
                tooltip: {
                    valueFormatter: function (value) {
                        return value + ' 小时';
                    }
                },
                label: {
                    show: true,
                    position: 'top',
                    formatter: '{c}',
                }
            },
        ]
    };

    if (option && typeof option === 'object') {
        myChart05.setOption(option);
    }

    // window.addEventListener('resize', myChart.resize);
}


/**
 * purchase
 * 加班 数据
 */

// 加班
function getovertime_sum() {
    $.ajax({
        url: strLin + "customSqlAccount/callProc",
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(['usp_getovertime_sum']),
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            let data=cdata.data;
            // //console.log(data);
            setovertime_text(data)
        }
    });

}

//赋值文本
function setovertime_text(data) {
    let todaynumber=0,thisweeknumbner=0,thismonthnumbner=0,todaynumber_hour=0,thisweeknumbner_hour=0,thismonthnumbner_hour=0;
    let p_number01=0,p_number02=0,p_number03=0,p_number04=0,h_number01=0,h_number02=0,h_number03=0,h_number04=0;
    if (data.length>0){

        todaynumber=isNull(data[0].todaynumber,0);
        thisweeknumbner=isNull(data[0].thisweeknumbner,0);
        thismonthnumbner=isNull(data[0].thismonthnumbner,0);
        todaynumber_hour=isNull(data[0].todaynumber_hour,0);
        thisweeknumbner_hour=isNull(data[0].thisweeknumbner_hour,0);
        thismonthnumbner_hour=isNull(data[0].thismonthnumbner_hour,0);

        p_number01=isNull(data[0].p_number01,0);
        p_number02=isNull(data[0].p_number02,0);
        p_number03=isNull(data[0].p_number03,0);
        // p_number04=data[0].p_number04;
        h_number01=isNull(data[0].h_number01,0);
        h_number02=isNull(data[0].h_number02,0);
        h_number03=isNull(data[0].h_number03,0);
        // h_number04=data[0].h_number04;


        $('#jb01').text('本日：'+ todaynumber);
        $('#jb02').text('本周：'+ thisweeknumbner);
        $('#jb03').text('本月：'+ thismonthnumbner);
        $('#jb04').text('本日：'+ todaynumber_hour.toFixed(1) + '小时');
        $('#jb05').text('本周：'+ thisweeknumbner_hour.toFixed(1)+ '小时');
        $('#jb06').text('本月：'+ thismonthnumbner_hour.toFixed(1)+ '小时');

        $('#jb11').text('年休假：'+ p_number01);
        $('#jb12').text('病假：'+ p_number02);
        $('#jb13').text('事假：'+ p_number03);
        // $('#jb14').text('其他：'+ p_number04);
        $('#jb15').text('年休假：'+ h_number01);
        $('#jb16').text('病假：'+ h_number02);
        $('#jb17').text('事假：'+ h_number03);
        // $('#jb18').text('其他：'+ h_number04);
    }else {

    }



}

//获取报加班形数据 加班人数
function getovertimeImg(val) {
    $.ajax({
        url: strLin + "customSqlAccount/callProc",
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(['usp_getovertimeImg_sum',val]),
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            let data=cdata.data;
            //console.log(data);
            setovertimeImgdata(data,val)
        }
    });

}

//转换图形数据的格式
function setovertimeImgdata(vdata,val) {
    var dataNew01=[],dataNew02=[];
    // var yearData=['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
    // var monthData=['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];

    let yearData=[];

    if (val==='月'){
        for (let i=1;i<32;i++){
            yearData.push(add0(i))
        }
    }else{
        for (let i=1;i<13;i++){
            yearData.push(add0(i))
        }
    }

    for (let index=0;index<yearData.length;index++){
        //根据 月份 名称过滤出对应的所有数据
        let jsonArrayNew = vdata.filter(function(item) {
            return Number(item.start_time) === Number(yearData[index])
        });
        //console.log(jsonArrayNew)
        if (jsonArrayNew.length>0){
            dataNew01.push(Number(jsonArrayNew[0].peopleNumber.toFixed(0)));

        }else{
            dataNew01.push(0);
        }
    }

    //console.log(dataNew01);
    setHistogram06(dataNew01,yearData)
}

//设置加班人数数据图形
function setHistogram06(vData01,vData02) {
    // var myChart = echarts.init(document.getElementById('Histogramby'));

    var dom = document.getElementById('Histogram06');
    var myChart06 = echarts.init(dom, null, {
        renderer: 'canvas',
        useDirtyRect: false
    });
    var app = {};

    var option;

    option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow',
                label: {
                    show: true
                }
            }
        },
        grid: {
            left:50,
            bottom:25
        },
        title: {
            text: '月/年加班人数趋势图'
        },
        xAxis: {
            data:vData02
            // name: '月',
            // data: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']
            // data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
        },
        yAxis: {
            name: '人数',
            type: 'value',
            axisLabel: {
                formatter: '{value}'
            }
        },
        series: [
            {
                name: '加班人数',
                type: 'line',
                data: vData01,
                tooltip: {
                    valueFormatter: function (value) {
                        return value + ' 人';
                    }
                },
                label: {
                    show: true,
                    position: 'top',
                    formatter: '{c}',
                }
            },
        ]
    };

    if (option && typeof option === 'object') {
        myChart06.setOption(option);
    }

    // window.addEventListener('resize', myChart.resize);
}


//获取加班图形数据 加班时长
function getovertimeImg_hour(val) {
    $.ajax({
        url: strLin + "customSqlAccount/callProc",
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(['usp_getovertimeImg_hour_sum',val]),
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            let data=cdata.data;
            //console.log(data);
            setovertimeImgdata_hour(data,val)
        }
    });

}

//转换图形数据的格式
function setovertimeImgdata_hour(vdata,val) {
    var dataNew01=[],dataNew02=[];
    // var yearData=['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
    // var monthData=['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];

    let yearData=[];

    if (val==='月'){
        for (let i=1;i<32;i++){
            yearData.push(add0(i))
        }
    }else{
        for (let i=1;i<13;i++){
            yearData.push(add0(i))
        }
    }

    for (let index=0;index<yearData.length;index++){
        //根据 月份 名称过滤出对应的所有数据
        let jsonArrayNew = vdata.filter(function(item) {
            return Number(item.start_time) === Number(yearData[index])
        });
        //console.log(jsonArrayNew)
        if (jsonArrayNew.length>0){
            dataNew01.push(Number(jsonArrayNew[0].peopleNumber.toFixed(0)));

        }else{
            dataNew01.push(0);
        }
    }

    //console.log(dataNew01);
    setHistogram07_hour(dataNew01,yearData)
}

//设置加班时长数据图形
function setHistogram07_hour(vData01,vData02) {
    // var myChart = echarts.init(document.getElementById('Histogramby'));

    var dom = document.getElementById('Histogram07');
    var myChart07 = echarts.init(dom, null, {
        renderer: 'canvas',
        useDirtyRect: false
    });
    var app = {};

    var option;

    option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow',
                label: {
                    show: true
                }
            }
        },
        grid: {
            left:50,
            bottom:25
        },
        title: {
            text: '月/年加班时长趋势图'
        },
        xAxis: {
            data:vData02
            // name: '月',
            // data: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']
            // data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
        },
        yAxis: {
            name: '小时',
            type: 'value',
            axisLabel: {
                formatter: '{value}'
            }
        },
        series: [
            {
                name: '加班时长',
                type: 'line',
                data: vData01,
                tooltip: {
                    valueFormatter: function (value) {
                        return value + ' 小时';
                    }
                },
                label: {
                    show: true,
                    position: 'top',
                    formatter: '{c}',
                }
            },
        ]
    };

    if (option && typeof option === 'object') {
        myChart07.setOption(option);
    }

    // window.addEventListener('resize', myChart.resize);
}


/**
 * purchase
 * 巡线 数据
 */

// 本月巡线数据
function getinspect_sum() {
    $.ajax({
        url: strLin + "customSqlAccount/callProc",
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(['usp_getinspect_main_sum']),
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            let data=cdata.data;
            // //console.log(data);
            // setinspect_text(data)
            cratertable(data,'reportContainer01')
            getinspectImg_NG()
        }
    });

}
//巡线NG百分比 图形转换数据
function getinspectImg_NG() {
    $.ajax({
        url: strLin + "customSqlAccount/callProc",
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(['usp_getinspect_main_sum_abc']),
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            let vdata=cdata.data;

            var dataNew01=[],dataNew02=[],dataNew03=[];
            var yearData=['BR', 'RG', 'TRB+HUB'];
            var categoryData=['A', 'B', 'C'];

            for (let index=0;index<yearData.length;index++){
                //根据 月份 名称过滤出对应的所有数据
                for (let i=0;i<categoryData.length;i++){
                    let jsonArrayNew = vdata.filter(function(item) {
                        return item.category01 === yearData[index] && item.team01 === categoryData[i]
                    });

                    if (jsonArrayNew.length>0){
                        if (categoryData[i]==='A'){
                            dataNew01.push(parseFloat(jsonArrayNew[0].ngzl));
                        }
                        if (categoryData[i]==='B'){
                            dataNew02.push(parseFloat(jsonArrayNew[0].ngzl));
                        }
                        if (categoryData[i]==='C'){
                            dataNew03.push(parseFloat(jsonArrayNew[0].ngzl));
                        }

                    }else{
                        if (categoryData[i]==='A'){
                            dataNew01.push(0);
                        }
                        if (categoryData[i]==='B'){
                            dataNew02.push(0);
                        }
                        if (categoryData[i]==='C'){
                            dataNew03.push(0);
                        }

                    }
                }

            }

            setHistogram089(dataNew01,dataNew02,dataNew03)
        }
    });
}

//设置保养数据图形
function setHistogram089(vData01,vData02,vData03) {
    var dom = document.getElementById('Histogram089');
    var myChart089 = echarts.init(dom, null, {
        renderer: 'canvas',
        useDirtyRect: false
    });
    var app = {};

    var option;

    option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow',
                label: {
                    show: true
                }
            }
        },
        legend: {
            x: 'right',
            data: ['A', 'B', 'C'],
            itemGap: 5
        },
        grid: {
            left:50,
            bottom:25
        },
        title: {
            x: 'center',
            top:10,
            fontSize: 16,
            text: '本月巡线合格率'
        },
        xAxis: {
            name: '',
            data: ['BR', 'RG', 'TRB+HUB']
            // data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
        },
        yAxis: {
            type: 'value',
            axisLabel: {
                formatter: '{value}%'
            }
        },
        series: [
            {
                name: 'A',
                type: 'bar',
                data: vData01,
                tooltip: {
                    valueFormatter: function (value) {
                        return value + ' %';
                    }
                },
                label: {
                    show: true,
                    position: 'top',
                    formatter: '{c}%',
                }
            },
            {
                name: 'B',
                type: 'bar',
                data: vData02,
                tooltip: {
                    valueFormatter: function (value) {
                        return value + ' %';
                    }
                },
                label: {
                    show: true,
                    position: 'top',
                    formatter: '{c}%',
                }
            },
            {
                name: 'C',
                type: 'bar',
                data: vData03,
                tooltip: {
                    valueFormatter: function (value) {
                        return value + ' %';
                    }
                },
                label: {
                    show: true,
                    position: 'top',
                    formatter: '{c}%',
                }
            }
        ]
    };

    if (option && typeof option === 'object') {
        myChart089.setOption(option);
    }

    // window.addEventListener('resize', myChart.resize);
}


// 本月品质检查汇总数 生成网格
// function getiQC_sum() {
//     $.ajax({
//         url: strLin + "customSqlAccount/callProc",
//         type: 'POST',
//         dataType: 'json',
//         data: JSON.stringify(['usp_getqc_main_sum']),
//         contentType: "application/json;charset=UTF-8",
//         success: function (cdata) {
//             let data=cdata.data;
//             //console.log(data);
//             cratertable(data,"reportContainer02")
//         }
//     });
//
// }

function cratertable(vData,divID) {
    //生成表格前先清除当前div容器中的标签
    var reportContainer = document.getElementById(divID);
    reportContainer.innerHTML = "";

    // 创建表格元素
    var table = document.createElement("table");

    // 设置表格样式
    table.style.width = "100%";
    table.style.borderCollapse = "collapse";

    // 创建表头行
    var thead = document.createElement("thead");
    var headerRow = document.createElement("tr");

    // 创建表头单元格并设置样式
    for (var key in vData[0]) {
        var headerCell = document.createElement("th");
        headerCell.textContent = gettabletr(key);
        headerCell.style.padding = "8px";
        // headerCell.style.backgroundColor = "#0000FF";
        headerCell.style.border = "0px solid #ddd";
        headerCell.style.fontSize = "16px";
        // headerCell.style.color = "white";
        headerCell.style.textAlign = "center";
        headerRow.appendChild(headerCell);

    }

    // 将表头行添加到表头元素
    thead.appendChild(headerRow);

    // 将表头元素添加到表格
    table.appendChild(thead);

    // 创建数据行
    var tbody = document.createElement("tbody");

    vData.forEach(function (rowData) {
        var dataRow = document.createElement("tr");

        // 创建数据单元格并设置样式
        for (var key in rowData) {
            var dataCell = document.createElement("td");
            dataCell.textContent = rowData[key];
            dataCell.style.padding = "3px";
            dataCell.style.border = "0px solid #ddd";
            // dataCell.style.color = "white";  // 设置字体颜色
            dataCell.style.fontSize = "16px";
            // dataCell.style.height = 25 + "px";
            // dataCell.style.width = 150 + "px";

            dataCell.style.textAlign = "center"; // 设置居中对齐
            // dataCell.style.backgroundColor = "#0000FF";
            dataRow.appendChild(dataCell);
        }

        // 将数据行添加到表体
        tbody.appendChild(dataRow);
    });

    // 将表体添加到表格
    table.appendChild(tbody);

    // 将表格添加到页面中的某个容器元素
    var container = document.getElementById(divID);
    container.appendChild(table);

}

//自定义标头名称
function gettabletr(val) {
    switch (val) {
        case 'category':
            return '本月外观检汇总';
            break;
        case 'category01':
            return '本月巡线汇总';
            break;
        case 'qtyAll':
            return '检查数';
            break;
        case 'qtyDefect':
            return '不合格数';
            break;
        case 'zl':
            return '不合格率';
            break;

        case 'allNumber':
            return '总巡线次数';
            break;
        case 'ngNumber':
            return 'NG次数';
            break;
        case 'ngzl':
            return '合格率百分比';
            break;
    }
}


//获取本年巡线合格率汇总图形数据
function getinspectImg() {
    $.ajax({
        url: strLin + "customSqlAccount/callProc",
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(['usp_getinspect_mainImg_sum']),
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            let data=cdata.data;
            //console.log(data);
            setinspectImgdata(data)
        }
    });

}

//转换图形数据的格式
function setinspectImgdata(vdata) {
    var dataNew01=[],dataNew02=[],dataNew03=[];
    var yearData=['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
    var categoryData=['BR', 'RG', 'TRB+HUB'];


    for (let index=0;index<yearData.length;index++){
        //根据 月份 名称过滤出对应的所有数据
        for (let i=0;i<categoryData.length;i++){
            let jsonArrayNew = vdata.filter(function(item) {
                return item.createTime === yearData[index] && item.category === categoryData[i]
            });

            if (jsonArrayNew.length>0){
                if (categoryData[i]==='RG'){
                    dataNew01.push(parseFloat(jsonArrayNew[0].zl));
                }
                if (categoryData[i]==='BR'){
                    dataNew02.push(parseFloat(jsonArrayNew[0].zl));
                }
                if (categoryData[i]==='TRB+HUB'){
                    dataNew03.push(parseFloat(jsonArrayNew[0].zl));
                }

            }else{
                if (categoryData[i]==='RG'){
                    dataNew01.push(0);
                }
                if (categoryData[i]==='BR'){
                    dataNew02.push(0);
                }
                if (categoryData[i]==='TRB+HUB'){
                    dataNew03.push(0);
                }

            }
        }

    }

    //console.log(dataNew01);
    //console.log(dataNew02);
    //console.log(dataNew03);
    setHistogram08(dataNew01,dataNew02,dataNew03)
}

//设置保养数据图形
function setHistogram08(vData01,vData02,vData03) {
    // var myChart = echarts.init(document.getElementById('Histogramby'));

    var dom = document.getElementById('Histogram08');
    var myChart08 = echarts.init(dom, null, {
        renderer: 'canvas',
        useDirtyRect: false
    });
    var app = {};

    var option;

    option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow',
                label: {
                    show: true
                }
            }
        },
        legend: {
            x: 'right',
            data: ['BR', 'RG', 'TRB+HUB'],
            itemGap: 5
        },

        grid: {
            left:50,
            bottom:25
        },
        title: {
            top:15,
            fontSize: 16,
            text: '本年度巡线合格率汇总'
        },
        xAxis: {
            name: '月',
            data: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']
            // data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
        },
        yAxis: {
            type: 'value',
            axisLabel: {
                formatter: '{value}%'
            }
        },
        series: [
            {
                name: 'BR',
                type: 'bar',
                data: vData02,
                tooltip: {
                    valueFormatter: function (value) {
                        return value + ' %';
                    }
                },
                label: {
                    show: true,
                    position: 'top',
                    formatter: '{c}%',
                }
            },
            {
                name: 'RG',
                type: 'bar',
                data: vData01,
                tooltip: {
                    valueFormatter: function (value) {
                        return value + ' %';
                    }
                },
                label: {
                    show: true,
                    position: 'top',
                    formatter: '{c}%',
                }
            },
            {
                name: 'TRB+HUB',
                type: 'bar',
                data: vData03,
                tooltip: {
                    valueFormatter: function (value) {
                        return value + ' %';
                    }
                },
                label: {
                    show: true,
                    position: 'top',
                    formatter: '{c}%',
                }
            }
        ]
    };

    if (option && typeof option === 'object') {
        myChart08.setOption(option);
    }

    // window.addEventListener('resize', myChart.resize);
}





/**
 * purchase
 * 制造生产不良 可动率 数据
 */

// 制造生产不良 可动率
function getquality_sum() {
    var data1 = $('#start').datebox('getValue');
    $.ajax({
        url: strLin + "customSqlAccount/callProc",
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(['usp_getquality_sum_sy',data1]),
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            let data=cdata.data;
            // //console.log(data);
            // setinspect_text(data)
            setquality_sumdata(data)
        }
    });

}

//对获取数据进行数据格式转换
function setquality_sumdata(vData) {
let lineMaindata=['RG','BR','TRB','HUB'];
let dataNew01=[],dataNew02=[];
for (let i=0;i<lineMaindata.length;i++){

    let jsonArrayNew = vData.filter(function(item) {
        return item.category === lineMaindata[i]
    });

    for (let index=0;index<jsonArrayNew.length;index++){
        let obj01;

        // obj01={'category':jsonArrayNew[index].category,'sid':jsonArrayNew[index].sid,'alias':jsonArrayNew[index].alias,
        //     'qtyAll':jsonArrayNew[index].qtyAll,'kdl':jsonArrayNew[index].kdl,'qtyAllsum':jsonArrayNew[index].qtyAllsum,'kdlsum':jsonArrayNew[index].kdlsum};

        if (index===0){
             obj01={'category':jsonArrayNew[index].category,'sid':jsonArrayNew[index].sid,'alias':jsonArrayNew[index].alias,
                    'qty_goods':jsonArrayNew[index].qty_goods,'qty_defect':jsonArrayNew[index].qty_defect,'kdl':jsonArrayNew[index].kdl,'kjl':jsonArrayNew[index].kjl,
                    'qty_goodssum':jsonArrayNew[index].qty_goodssum,'qty_defectsum':jsonArrayNew[index].qty_defectsum,'kdlsum':jsonArrayNew[index].kdlsum
             };
        }else{
             obj01={'category':'','sid':jsonArrayNew[index].sid,'alias':jsonArrayNew[index].alias,
                 'qty_goods':jsonArrayNew[index].qty_goods,'qty_defect':jsonArrayNew[index].qty_defect,'kdl':jsonArrayNew[index].kdl,'kjl':jsonArrayNew[index].kjl,
                 'qty_goodssum':jsonArrayNew[index].qty_goodssum,'qty_defectsum':jsonArrayNew[index].qty_defectsum,'kdlsum':jsonArrayNew[index].kdlsum
             };
        }
         // let obj02={'alias':jsonArrayNew[index].alias,'qtyAllsum':jsonArrayNew[index].qtyAllsum,'kdlsum':jsonArrayNew[index].kdlsum}

        dataNew01.push(obj01);
        // dataNew02.push(obj02);

    }

    // dataNew01.push({'category':'','sid':'','alias':'','qtyAll':'','kdl':''});
    // dataNew02.push({'alias':'','qtyAllsum':'','kdlsum':''});

    cratertable_new(dataNew01,'kdl');
}


}

function cratertable_new(vData,divID) {
    //生成表格前先清除当前div容器中的标签
    var reportContainer = document.getElementById(divID);
    reportContainer.innerHTML = "";

    // 创建表格元素
    var table = document.createElement("table");

    // 设置表格样式
    table.style.width = "100%";
    table.style.borderCollapse = "collapse";

    // 创建表头行
    var thead = document.createElement("thead");
    var headerRow = document.createElement("tr");

    // 创建表头单元格并设置样式
    for (var key in vData[0]) {
        var headerCell = document.createElement("th");
        headerCell.textContent = gettabletrNew(key);
        // headerCell.style.padding = "8px";
        // headerCell.style.backgroundColor = "#0000FF";
        headerCell.style.border = "1px solid #ddd";
        headerCell.style.fontSize = "16px";
        // headerCell.style.color = "white";
        headerCell.style.textAlign = "center";
        headerRow.appendChild(headerCell);

    }

    // 将表头行添加到表头元素
    thead.appendChild(headerRow);

    // 将表头元素添加到表格
    table.appendChild(thead);

    // 创建数据行
    var tbody = document.createElement("tbody");

    vData.forEach(function (rowData) {
        var dataRow = document.createElement("tr");

        // 创建数据单元格并设置样式
        for (var key in rowData) {
            var dataCell = document.createElement("td");
            dataCell.textContent = rowData[key];
            dataCell.style.padding = "1px";
            dataCell.style.border = "1px solid #ddd";
            // dataCell.style.color = "white";  // 设置字体颜色
            dataCell.style.fontSize = "16px";
            dataCell.style.height = 20 + "px";
            // dataCell.style.width = 150 + "px";

            dataCell.style.textAlign = "center"; // 设置居中对齐

            if (key==='kjl'){
                dataCell.style.width = 100 + "px";
            }

            if (key==='qty_defect' || key==='qty_defectsum'){
                dataCell.style.color = "red";  // 设置字体颜色
            }

            if (key==='qty_defect' || key==='qty_defectsum' || key==='qty_goods' || key==='qty_goodssum'){
                dataCell.style.textAlign = "right";
            }

            // dataCell.style.backgroundColor = "#0000FF";
            dataRow.appendChild(dataCell);
        }

        // 将数据行添加到表体
        tbody.appendChild(dataRow);
    });

    // 将表体添加到表格
    table.appendChild(tbody);

    // 将表格添加到页面中的某个容器元素
    var container = document.getElementById(divID);
    container.appendChild(table);

}

//自定义标头名称
function gettabletrNew(val) {
    switch (val) {
        case 'category':
            return '';
            break;
        case 'sid':
            return '工程';
            break;
        case 'alias':
            return '线';
            break;

        case 'qty_goods':
            return '良品';
            break;
        case 'qty_defect':
            return '不良品';
            break;
        case 'kdl':
            return '可动率';
            break;

        case 'qty_goodssum':
            return '总良品';
            break;
        case 'qty_defectsum':
            return '总不良品';
            break;
        case 'kdlsum':
            return '总可动率';
            break;

        case 'kjl':
            return ' ';
            break;
    }
}



/**
 * purchase
 * 制造生产不良 不良率 数据
 */

// 制造生产不良 不良率
function getquality_zl() {
    $.ajax({
        url: strLin + "customSqlAccount/callProc",
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(['usp_getquality_sy']),
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            let data=cdata.data;
            console.log(data);

            // if (data.length>0){
            //     $('#bllDate01').text('导入数据至:'+ data[0].produceDate);
            // }
            cratertable_04(data,'reportContainer04');
            getqualityImg_ZL(data);
        }
    });

}

function cratertable_04(vData,divID) {
    //生成表格前先清除当前div容器中的标签
    var reportContainer = document.getElementById(divID);
    reportContainer.innerHTML = "";

    // 创建表格元素
    var table = document.createElement("table");

    // 设置表格样式
    table.style.width = "100%";
    table.style.borderCollapse = "collapse";

    // 创建表头行
    var thead = document.createElement("thead");
    var headerRow = document.createElement("tr");

    // 创建表头单元格并设置样式
    for (var key in vData[0]) {
        // if (key !=='produceDate'){
            var headerCell = document.createElement("th");
            headerCell.textContent = gettabletr_04(key);
            headerCell.style.padding = "8px";
            // headerCell.style.backgroundColor = "#0000FF";
            headerCell.style.border = "0px solid #ddd";
            headerCell.style.fontSize = "16px";
            // headerCell.style.color = "white";
            headerCell.style.textAlign = "center";
            headerRow.appendChild(headerCell);
        // }
    }

    // 将表头行添加到表头元素
    thead.appendChild(headerRow);

    // 将表头元素添加到表格
    table.appendChild(thead);

    // 创建数据行
    var tbody = document.createElement("tbody");

    vData.forEach(function (rowData) {
        var dataRow = document.createElement("tr");

        // 创建数据单元格并设置样式
        for (var key in rowData) {
            // if (key !=='produceDate'){
                var dataCell = document.createElement("td");
                dataCell.textContent = rowData[key];
                dataCell.style.padding = "3px";
                dataCell.style.border = "0px solid #ddd";
                // dataCell.style.color = "white";  // 设置字体颜色
                dataCell.style.fontSize = "16px";
                // dataCell.style.height = 25 + "px";
                // dataCell.style.width = 150 + "px";

                if (rowData['zl']>rowData['defect_rate'] && key==='zl'){
                    dataCell.style.color = "red";
                }

                dataCell.style.textAlign = "center"; // 设置居中对齐
                // dataCell.style.backgroundColor = "#0000FF";
                dataRow.appendChild(dataCell);
            // }

        }

        // 将数据行添加到表体
        tbody.appendChild(dataRow);
    });

    // 将表体添加到表格
    table.appendChild(tbody);

    // 将表格添加到页面中的某个容器元素
    var container = document.getElementById(divID);
    container.appendChild(table);

}

//自定义标头名称
function gettabletr_04(val) {
    switch (val) {
        case 'category03':
            return '产品';
            break;
        case 'qtyAll':
            return '检查数';
            break;
        case 'qtyDefect':
            return 'NG数';
            break;
        case 'zl':
            return '不良率';
            break;
        case 'defect_rate':
            return '不良率目标';
            break;
        case 'produceDate':
            return '更新日期';
            break;

    }
}



//制造生产不良率  图形转换数据
function getqualityImg_ZL(vdata) {
    var dataNew01=[],dataNew02=[],dataNew03=[];
    var categoryData=['BR', 'RG', 'TRB', 'HUB'];

    //根据 月份 名称过滤出对应的所有数据
    for (let i=0;i<categoryData.length;i++){
        let jsonArrayNew = vdata.filter(function(item) {
            return item.category03 === categoryData[i]
        });

        if (jsonArrayNew.length>0){
            dataNew01.push(parseFloat(jsonArrayNew[0].zl));
            dataNew02.push(parseFloat(jsonArrayNew[0].defect_rate));
            dataNew03.push(parseFloat(jsonArrayNew[0].qtyDefect));
        }else{
            dataNew01.push(0);
            dataNew02.push(0);
            dataNew03.push(0);
        }
    }

    setHistogram10(categoryData,dataNew01,dataNew02,dataNew03)

}

//设置保养数据图形
function setHistogram10(vData01,vData02,vData03,vData04) {
    var dom = document.getElementById('Histogram010');
    var myChart10 = echarts.init(dom, null, {
        renderer: 'canvas',
        useDirtyRect: false
    });
    var app = {};

    var option;

    option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow',
                label: {
                    show: true
                }
            }
        },
        grid: {
            left:50,
            bottom:25
        },
        legend: {
            x: 'right',
            data: ['NG数','不良率', '不良率目标'],
            itemGap: 5
        },
        title: {
            x: 'left',
            top:10,
            fontSize: 16,
            text: '本月工程内不良汇总'
        },
        xAxis: {
            name: '',
            data: vData01
            // data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
        },
        // yAxis: {
        //     type: 'value',
        //     axisLabel: {
        //         formatter: '{value}%'
        //     }
        // },

        yAxis: [
            {
                type: 'value',
                // name: 'NG数',
                // min: 0,
                // max: 250,
                // interval: 50,
                axisLabel: {
                    formatter: '{value}'
                }
            },
            {
                type: 'value',
                // name: '不良率',
                position: 'right',
                // min: 0,
                // max: 25,
                // interval: 0.5,
                axisLabel: {
                    formatter: '{value}%'
                }
            },
        ],

        series: [
            {
                name: 'NG数',
                type: 'bar',
                barWidth:30,
                yAxisIndex: 0,
                tooltip: {
                    valueFormatter: function (value) {
                        return value;
                    }
                },
                label: {
                    show: true,
                    position: 'insideBottom',
                    formatter: '{c}',
                },
                data: vData04
            },
            {
                name: '不良率',
                type: 'line',
                yAxisIndex: 1,
                color:'#FF88C2',
                lineStyle: {
                    normal: {
                        width: 3 // 设置线条宽度为3
                    }
                },
                tooltip: {
                    valueFormatter: function (value) {
                        return value + ' %';
                    }
                },
                label: {
                    show: true,
                    position: 'top',
                    formatter: '{c}%',
                    color:'#FF88C2',
                },
                data: vData02
            },
            {
                name: '不良率目标',
                type: 'line',
                yAxisIndex: 1,
                color:'#66DD00',
                lineStyle: {
                    normal: {
                        width: 3 // 设置线条宽度为3
                    }
                },
                tooltip: {
                    valueFormatter: function (value) {
                        return value + ' %';
                    }
                },
                label: {
                    show: true,
                    position: 'bottom',
                    formatter: '{c}%',
                    color:'#66DD00'

                },
                data: vData03
            }
        ]
    };

    if (option && typeof option === 'object') {
        myChart10.setOption(option);
    }

    // window.addEventListener('resize', myChart.resize);
}





// 品质检查不良 不良率
function getQC_zl() {
    $.ajax({
        url: strLin + "customSqlAccount/callProc",
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(['usp_getQC_sy_zl']),
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            let data=cdata.data;
            console.log(data);

            // if (data.length>0){
            //     $('#bllDate02').text('导入数据至:'+ data[0].produceDate);
            // }

            cratertable_05(data,'reportContainer05')
            getQCImg_ZL(data);
        }
    });

}

function cratertable_05(vData,divID) {
    //生成表格前先清除当前div容器中的标签
    var reportContainer = document.getElementById(divID);
    reportContainer.innerHTML = "";

    // 创建表格元素
    var table = document.createElement("table");

    // 设置表格样式
    table.style.width = "100%";
    table.style.borderCollapse = "collapse";

    // 创建表头行
    var thead = document.createElement("thead");
    var headerRow = document.createElement("tr");

    // 创建表头单元格并设置样式
    for (var key in vData[0]) {
        // if (key !=='produceDate') {
            var headerCell = document.createElement("th");
            headerCell.textContent = gettabletr_05(key);
            headerCell.style.padding = "8px";
            // headerCell.style.backgroundColor = "#0000FF";
            headerCell.style.border = "0px solid #ddd";
            headerCell.style.fontSize = "16px";
            // headerCell.style.color = "white";
            headerCell.style.textAlign = "center";
            headerRow.appendChild(headerCell);
        // }
    }

    // 将表头行添加到表头元素
    thead.appendChild(headerRow);

    // 将表头元素添加到表格
    table.appendChild(thead);

    // 创建数据行
    var tbody = document.createElement("tbody");

    vData.forEach(function (rowData) {
        var dataRow = document.createElement("tr");

        // 创建数据单元格并设置样式
        for (var key in rowData) {
            // if (key !=='produceDate') {
                var dataCell = document.createElement("td");
                dataCell.textContent = rowData[key];
                dataCell.style.padding = "3px";
                dataCell.style.border = "0px solid #ddd";
                // dataCell.style.color = "white";  // 设置字体颜色
                dataCell.style.fontSize = "16px";
                // dataCell.style.height = 25 + "px";
                // dataCell.style.width = 150 + "px";

                if (rowData['QCZL'] > rowData['defect_rate'] && key === 'QCZL') {
                    dataCell.style.color = "red";
                }

                dataCell.style.textAlign = "center"; // 设置居中对齐
                // dataCell.style.backgroundColor = "#0000FF";
                dataRow.appendChild(dataCell);
            // }
        }

        // 将数据行添加到表体
        tbody.appendChild(dataRow);
    });

    // 将表体添加到表格
    table.appendChild(tbody);

    // 将表格添加到页面中的某个容器元素
    var container = document.getElementById(divID);
    container.appendChild(table);

}

//自定义标头名称
function gettabletr_05(val) {
    switch (val) {
        case 'category04':
            return '产品';
            break;
        case 'QCqtyAll':
            return '检查数';
            break;
        case 'QCqtyDefect':
            return 'NG数';
            break;
        case 'QCZL':
            return '不良率';
            break;
        case 'defect_rate':
            return '不良率目标';
            break;
        case 'produceDate':
            return '更新日期';
            break;
    }
}



//制造生产不良率  图形转换数据
function getQCImg_ZL(vdata) {
    var dataNew01=[],dataNew02=[],dataNew03=[];
    var categoryData=['BR', 'RG', 'TRB', 'HUB'];

    //根据 月份 名称过滤出对应的所有数据
    for (let i=0;i<categoryData.length;i++){
        let jsonArrayNew = vdata.filter(function(item) {
            return item.category04 === categoryData[i]
        });

        if (jsonArrayNew.length>0){
            dataNew01.push(parseFloat(jsonArrayNew[0].QCZL));
            dataNew02.push(parseFloat(jsonArrayNew[0].defect_rate));
            dataNew03.push(parseFloat(jsonArrayNew[0].QCqtyDefect));
        }else{
            dataNew01.push(0);
            dataNew02.push(0);
            dataNew03.push(0);
        }
    }

    setHistogram11(categoryData,dataNew01,dataNew02,dataNew03)

}

//设置保养数据图形
function setHistogram11(vData01,vData02,vData03,vData04) {
    var dom = document.getElementById('Histogram011');
    var myChart11 = echarts.init(dom, null, {
        renderer: 'canvas',
        useDirtyRect: false
    });
    var app = {};

    var option;

    option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow',
                label: {
                    show: true
                }
            }
        },
        grid: {
            left:50,
            bottom:25
        },
        legend: {
            x: 'right',
            data: ['NG数','不良率', '不良率目标'],
            itemGap: 5
        },
        title: {
            x: 'left',
            top:10,
            fontSize: 16,
            text: '本月外观检不良汇总'
        },
        xAxis: {
            name: '',
            data: vData01
            // data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
        },
        yAxis: [
            {
                type: 'value',
                // name: 'NG数',
                // min: 0,
                // max: 250,
                // interval: 50,
                axisLabel: {
                    formatter: '{value}'
                }
            },
            {
                type: 'value',
                // name: '不良率',
                position: 'right',
                // min: 0,
                // max: 25,
                // interval: 0.5,
                axisLabel: {
                    formatter: '{value}%'
                }
            },
        ],

        series: [
            {
                name: 'NG数',
                type: 'bar',
                barWidth:30,
                yAxisIndex: 0,
                tooltip: {
                    valueFormatter: function (value) {
                        return value;
                    }
                },
                label: {
                    show: true,
                    position: 'insideBottom',
                    formatter: '{c}',
                },
                data: vData04
            },
            {
                name: '不良率',
                type: 'line',
                yAxisIndex: 1,
                color:'#FF88C2',
                lineStyle: {
                    normal: {
                        width: 3 // 设置线条宽度为3
                    }
                },
                tooltip: {
                    valueFormatter: function (value) {
                        return value + ' %';
                    }
                },
                label: {
                    show: true,
                    position: 'top',
                    formatter: '{c}%',
                    color:'#FF88C2',
                },
                data: vData02
            },
            {
                name: '不良率目标',
                type: 'line',
                yAxisIndex: 1,
                color:'#66DD00',
                lineStyle: {
                    normal: {
                        width: 3 // 设置线条宽度为3
                    }
                },
                tooltip: {
                    valueFormatter: function (value) {
                        return value + ' %';
                    }
                },
                label: {
                    show: true,
                    position: 'bottom',
                    formatter: '{c}%',
                    color:'#66DD00'

                },
                data: vData03
            }
        ]
    };

    if (option && typeof option === 'object') {
        myChart11.setOption(option);
    }

    // window.addEventListener('resize', myChart.resize);
}



/**
 * purchase
 * 产线状态
 */
function linestate() {
    $.ajax({
        url: strLin + "customSqlAccount/callProc",
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(['sy_line_state']),
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            let data=cdata.data;
            setlinestate_data(data)
        }
    });
}

function setlinestate_data(vData) {
    let dataNew=[];
    if (vData){
        let maxnumber=vData[0].number;
        let dataNew01 = vData.filter(function(item) {return item.group_state === 1});
        let dataNew02 = vData.filter(function(item) {return item.group_state === 2});
        let dataNew03 = vData.filter(function(item) {return item.group_state === 3});
        let dataNew04 = vData.filter(function(item) {return item.group_state === 4});
        let dataNew05 = vData.filter(function(item) {return item.group_state === 5});
        let dataNew06 = vData.filter(function(item) {return item.group_state === 6});

        for (let i=0;i<maxnumber;i++){
            let Obj={'sid01':'',"running_state01":'','sid02':'',"running_state02":'','sid03':'',"running_state03":'',
                'sid04':'',"running_state04":'','sid05':'',"running_state05":'','sid06':'',"running_state06":''};

            if (dataNew01.length>i){
                Obj.sid01=dataNew01[i].sid;
                Obj.running_state01=dataNew01[i].running_state;
            }

            if (dataNew02.length>i){
                Obj.sid02=dataNew02[i].sid;
                Obj.running_state02=dataNew02[i].running_state;
            }

            if (dataNew03.length>i){
                Obj.sid03=dataNew03[i].sid;
                Obj.running_state03=dataNew03[i].running_state;
            }

            if (dataNew04.length>i){
                Obj.sid04=dataNew04[i].sid;
                Obj.running_state04=dataNew04[i].running_state;
            }

            if (dataNew05.length>i){
                Obj.sid05=dataNew05[i].sid;
                Obj.running_state05=dataNew05[i].running_state;
            }

            if (dataNew06.length>i){
                Obj.sid06=dataNew06[i].sid;
                Obj.running_state06=dataNew06[i].running_state;
            }

            dataNew.push(Obj);

        }


        console.log(dataNew)

    }

    cratertable_linestate(dataNew,'linestate')
}


function cratertable_linestate(vData,divID) {
    //生成表格前先清除当前div容器中的标签
    var reportContainer = document.getElementById(divID);
    reportContainer.innerHTML = "";

    // 创建表格元素
    var table = document.createElement("table");

    // 设置表格样式
    table.style.width = "100%";
    table.style.borderCollapse = "collapse";

    // 创建表头行
    var thead = document.createElement("thead");
    var headerRow = document.createElement("tr");

    // 创建表头单元格并设置样式
    for (var key in vData[0]) {
        var headerCell = document.createElement("th");
        headerCell.textContent = gettabletr_linestate(key);
        // headerCell.style.padding = "8px";
        // headerCell.style.backgroundColor = "#0000FF";
        headerCell.style.border = "1px solid #ddd";
        headerCell.style.fontSize = "16px";
        // headerCell.style.color = "white";
        headerCell.style.textAlign = "center";
        headerRow.appendChild(headerCell);

    }

    // 将表头行添加到表头元素
    thead.appendChild(headerRow);

    // 将表头元素添加到表格
    table.appendChild(thead);

    // 创建数据行
    var tbody = document.createElement("tbody");

    vData.forEach(function (rowData) {
        var dataRow = document.createElement("tr");

        // 创建数据单元格并设置样式
        for (var key in rowData) {
            var dataCell = document.createElement("td");
            dataCell.textContent = rowData[key];
            dataCell.style.padding = "1px";
            dataCell.style.border = "1px solid #ddd";
            // dataCell.style.color = "white";  // 设置字体颜色
            dataCell.style.fontSize = "16px";
            dataCell.style.height = 20 + "px";
            // dataCell.style.width = 150 + "px";
            dataCell.style.textAlign = "center"; // 设置居中对齐

            if (key==='running_state01' || key==='running_state02' || key==='running_state03' || key==='running_state04' || key==='running_state05' || key==='running_state06'){
                // dataCell.style.color = "red";  // 设置字体颜色
                // dataCell.style.color = gettableColor_linestate(rowData[key]);
                dataCell.style.backgroundColor=gettableColor_linestate(rowData[key]);
            }

            dataRow.appendChild(dataCell);
        }

        // 将数据行添加到表体
        tbody.appendChild(dataRow);
    });

    // 将表体添加到表格
    table.appendChild(tbody);

    // 将表格添加到页面中的某个容器元素
    var container = document.getElementById(divID);
    container.appendChild(table);

}

//自定义标头名称
function gettabletr_linestate(val) {
    switch (val) {
        case 'sid01':
            return 'RG产线';
            break;
        case 'sid02':
            return 'RG产线';
            break;
        case 'sid03':
            return 'RG产线';
            break;

        case 'sid04':
            return 'BR产线';
            break;
        case 'sid05':
            return 'TRB产线';
            break;
        case 'sid06':
            return 'TRB产线';
            break;

        case 'running_state01':
            return 'RG状态';
            break;
        case 'running_state02':
            return 'RG状态';
            break;
        case 'running_state03':
            return 'RG状态';
            break;

        case 'running_state04':
            return 'BR状态';
            break;
        case 'running_state05':
            return 'TRB状态';
            break;
        case 'running_state06':
            return 'TRB状态';
            break;

        default :
            return ' ';
            break;
    }
}


function gettableColor_linestate(val) {
    switch (val) {
        case '稼动':
            return '#99FF99';
            break;
        case '保养':
            return '#FFFF77';
            break;
        case '型切':
            return '#FFDDAA';
            break;
        case '等料':
            return '#99BBFF';
            break;
        case '计停':
            return '#D1BBFF';
            break;
        case '维修':
            return '#FFB7DD';
            break;
        case '维修中':
            return '#FFB7DD';
            break;
        case '待确认':
            return '#00BBFF';
            break;
        case '待部品':
            return '#FFDD55';
            break;
        // default:
        //     return '';
        //     break;
    }
}


/******************************************************/

function setcom() {
    $.ajax({
        url: strLin + "simpleBase/selectAll",
        type: 'post',
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            let  data=cdata.data;
            let result01 = data.filter(function(item) {return item.category === '优先事项';});
            let result02 = data.filter(function(item) {return item.category === '优先事项紧急程度';});
            let result03 = data.filter(function(item) {return item.category === '优先事项项目进展状态';});
            let result04 = data.filter(function(item) {return item.category === '优先事项验收结果';});
            result01.sort(function (x, y) { return x['seq'] - y['seq'] });
            $('#category').combobox({data:result01, required:true, limitToList:true, panelHeight:200, valueField:'sid', textField:'sid',});
            $('#level').combobox({data:result02, required:true, limitToList:true, panelHeight:80, valueField:'sid', textField:'sid',});
            // $('#progress').combobox({data:result03, required:false, limitToList:true, panelHeight:200, valueField:'sid', textField:'sid',});
            $('#result').combobox({data:result04, required:false, limitToList:true, panelHeight:80, valueField:'sid', textField:'sid',});

        },
    });

    // $.ajax({
    //     url: strLin + "department/selectAll",
    //     type: 'post',
    //     contentType: "application/json;charset=UTF-8",
    //     success: function (cdata) {
    //         let  data=cdata.data;
    //         console.log(data);
    //         // 担当部门
    //         $('#principalDepartment').combobox({data:data, required:true, limitToList:true, panelHeight:200, valueField:'sid', textField:'sid',
    //             onSelect: function(record){
    //                 // 获取选中的值
    //                 // console.log(record)
    //                 var value = record.sid;
    //                 let result01 = employee_Data.filter(function(item) {return item.departmentSid === value;});
    //                 $('#principal').combobox({data:result01, required:true, limitToList:true, panelHeight:200, valueField:'sid', textField:'sname',});
    //
    //                 // $.ajax({
    //                 //     url: strLin + "customSqlAccount/callProc",
    //                 //     type: 'post',
    //                 //     data: JSON.stringify(['usp_getemployee',value]),
    //                 //     contentType: "application/json;charset=UTF-8",
    //                 //     success: function (cdata) {
    //                 //         let  data=cdata.data;
    //                 //         console.log(data);
    //                 //         $('#principal').combobox({data:data, required:true, limitToList:true, panelHeight:200, valueField:'sid', textField:'sname',});
    //                 //     }
    //                 // })
    //
    //
    //             }
    //         });
    //         // 协助部门
    //         $('#assistDepartment').combobox({data:data, required:false, limitToList:true, panelHeight:200, valueField:'sid', textField:'sid',});
    //     },
    // });

    //员工信息
    $.ajax({
        url: strLin + "employee/selectAll",
        type: 'post',
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            let  data=cdata.data;
            // console.log(data);
            employee_Data=data;
            let result01 = data.filter(function(item) {return item.sid === Strusersid;});
            userdepartment=result01[0].departmentSid;
            $('#principal').combobox({data:data, required:false, limitToList:true, panelHeight:200, valueField:'sid', textField:'sname',});
            $("#departmentSid").textbox('setValue',userdepartment);
            // $("#createUser").textbox('setValue',Strusername);

            //担当部门
            $('#principalDepartment').combobox({data:RemoveDuplicates(data), required:true, limitToList:true, panelHeight:200, valueField:'departmentSid', textField:'departmentSid',
                onSelect: function(record){
                    // 获取选中的值
                    // console.log(record)
                    var value = record.departmentSid;
                    let result01 = employee_Data.filter(function(item) {return item.departmentSid === value;});
                    $('#principal').combobox({data:result01, required:false, limitToList:true, panelHeight:200, valueField:'sid', textField:'sname',});

                    let result02 = employee_Data.filter(function(item) {return item.departmentSid ===value && item.sid ===Strusersid});
                    if (result02.length>0){
                        // status('A',0);
                        status('B',1);
                    }else{
                        // status('A',0);
                        status('B',0);
                    }
                }
            });
            // 协助部门
            $('#assistDepartment').combobox({data:RemoveDuplicates(data), required:false, limitToList:true, panelHeight:200, valueField:'departmentSid', textField:'departmentSid',});

            // 提出者部门
            $('#departmentSid').combobox({data:RemoveDuplicates(data), required:true, limitToList:true, panelHeight:200, valueField:'departmentSid', textField:'departmentSid',
                onSelect: function(record){
                    var value = record.departmentSid;
                    let result01 = employee_Data.filter(function(item) {return item.departmentSid === value;});
                    $('#sponsor').combobox({data:result01, required:true, limitToList:true, panelHeight:200, valueField:'sid', textField:'sname',});
                }
            });

        },
    });


    $('#postponeAuditFlag').combobox({data:[{id:1,sid:'通过'},{id:2,sid:'不通过'}], required:true, limitToList:true, panelHeight:80, valueField:'id', textField:'sid',});

}

//去除重复
function RemoveDuplicates(val) {
    // 假设有一个包含对象的数组
    var objectArray = val;

// 用于去重的对象
    var uniqueObject = {};

// 用于存放去重后的对象数组
    var uniqueObjectArray = [];

// 遍历原始数组
    objectArray.forEach(function(obj) {
        // 使用对象的 id 属性作为唯一标识
        var departmentSid = obj.departmentSid;
        // 如果 uniqueObject 中没有该 id，表示尚未遇到重复的对象
        if (departmentSid){
            if (!uniqueObject[departmentSid]) {
                uniqueObject[departmentSid] = obj;
                uniqueObjectArray.push(obj);
            }
        }
    });
    // console.log(uniqueObjectArray);
    return uniqueObjectArray;
}

function Priorities_add(val) {
    if (val===0){
        status('A',1);
        status('B',0);
        $("#departmentSid").combobox('setValue',userdepartment);
        // $("#createUser").combobox('setValue',Strusersid);
        $("#sponsor").combobox('setValue',Strusersid);
    }else{

        status('A',0);
        status('B',0);

        if (Strusersid==='6001' || val.sponsorSid===Strusersid){
            status('A',1);
            // status('B',0);
        }

        let result01 = employee_Data.filter(function(item) {return item.departmentSid ===val.principalDepartment && item.sid ===Strusersid});
        if (result01.length>0){
            // status('A',0);
            status('B',1);
        }else{
            // status('A',0);
            // status('B',0);
        }

        $('#ff').form('load',val);
        $("#sponsor").combobox('setValue',val.sponsorSid);
    }

    $('#Priorities_win').window('open');
}

function btn_copyA() {
    let load= {"id": "0"};
    $('#ff').form('load',load);
    $.messager.show({title:'提示', msg:'复制完成，点击保存生成一个新的未完成事项单！'});
}
function btn_saveA() {
    var formData = {}; // 创建一个空对象来存放数据

    // 选择所有表单中的输入字段
    $('#ff input').each(function() {
        var fieldName = $(this).attr('name'); // 获取字段名
        var fieldValue = $(this).val(); // 获取字段值
        formData[fieldName] = fieldValue; // 将数据添加到对象
    });
    delete formData.createUser;
    let url;
    if (formData.id>0){
        url=strLin + 'priorityMain/updateByPrimaryKeySelective'
    }else{
        url=strLin + 'priorityMain/insertSelective'
    }

    const sponsorSid = $('#sponsor').combobox('getValue');
    console.log('提出者员工编号：', sponsorSid);
    formData['sponsor'] = sponsorSid;
    console.log('优先事项请求保存的数据是：', formData);
    $.ajax({
        headers: {"usersid":Strusersid},
        url: url,
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(formData),
        contentType: "application/json;charset=UTF-8",
        success: function (data) {
            if (data.code != 1){
                $.messager.show({title:'提示', msg:data.msg});
                return;
            }else{
                btn_cancelA();
                Priorities_Refresh();
                $.messager.show({title:'提示', msg:'保存成功！！！'});
            }

        }
    });


}

function btn_deleteA(val) {
    var formData = {}; // 创建一个空对象来存放数据
    // 选择所有表单中的输入字段
    $('#ff input').each(function() {
        var fieldName = $(this).attr('name'); // 获取字段名
        var fieldValue = $(this).val(); // 获取字段值
        formData[fieldName] = fieldValue; // 将数据添加到对象
    });
    if (formData.id>0){
        // let strSQL={id:formData.id,state:val,result:formData.result};
        formData.state=val;
        let strSQL=formData;
        let mesStr;
        if (val===0){
            let result01 = employee_Data.filter(function(item) {return item.userGrade ==='总经理' && item.sid ===Strusersid });
            if (result01.length>0 || $('#sponsor').combobox('getValue')===Strusersid || Strusersid==='6001'){
                mesStr='确定关闭当前事项吗？'
            }else{
                $.messager.show({title:'提示', msg:'当前登录账号无权限关闭事项！！！'});
                return;
            }
        }else{mesStr='当前删除为永久删除，不可恢复，确定删除吗？'}
        // $.messager.defaults = {ok: "确定", cancel: "取消", width: 300, closable: false};
        $.messager.confirm('确认', mesStr, function (r) {
            if (r) {

                $.ajax({
                    headers: {"usersid":Strusersid},
                    url: strLin + 'priorityMain/updateByPrimaryKeySelective',
                    type: 'POST',
                    dataType: 'json',
                    data: JSON.stringify(strSQL),
                    contentType: "application/json;charset=UTF-8",
                    success: function (data) {
                        if (data.code != 1){
                            $.messager.show({title:'提示', msg:data.msg});
                            return;
                        }else{
                            btn_cancelA();
                            Priorities_Refresh();
                            $.messager.show({title:'提示', msg:'保存成功！！！'});
                        }

                    }
                });
            }
        });
    }
}

function btn_cancelA() {

    let load= {
        "billDate": getDay(0),
        "departmentSid": "",
        "category": "",
        "content": "",
        "level": "",
        "deadLine": '',
        "principalDepartment": "",
        "principal": "",
        "assistDepartment": "",
        "solution": "",
        "startTime": '',
        "endTime": '',
        "intervalTime": "",
        "progress01": "",
        "result": "",
        "createUser": "",
        "id": "0"
    };

    $('#ff').form('load',load);
    $('#Priorities_win').window('close');
}

function btn_cancelB() {
    let load= {
        "op1emarkR01": "",
        "op1emarkR02": "",
        "detailid01": 0,
        "detailid02": 0,
        "op2emarkR01": '',
        "op2emarkR02": "",
        "detailid03": 0,
        "detailid04": 0,
        'op1Time01':'',
        'op1Time02':'',
        'op2Time01':'',
        'op2Time02':'',
        "id": "0"
    };

    $('#fff').form('load',load);
    $('#Priorities_winB').window('close');
}

function status(AorB,val) {

    if (AorB==='A'){
        //A区域
        $('#departmentSid').combobox({readonly:(val===1?false:true)});
        $('#sponsor').combobox({readonly:(val===1?false:true)});
        $('#level').combobox({readonly:(val===1?false:true)});
        $('#category').combobox({readonly:(val===1?false:true)});
        $('#principalDepartment').combobox({readonly:(val===1?false:true)});
        $('#content').textbox({readonly:(val===1?false:true)});
        $('#billDate').datebox({readonly:(val===1?false:true)});
        $('#deadLine').datebox({readonly:(val===1?false:true)});
        $('#result').combobox({readonly:(val===1?false:true)});
        $('#notiTime').datetimebox({readonly:(val===1?false:true)});
    }else{
        //B区域
        $('#principal').combobox({readonly:(val===1?false:true)});
        $('#assistDepartment').combobox({readonly:(val===1?false:true)});
        $('#solution').textbox({readonly:(val===1?false:true)});
        $('#startTime').datebox({readonly:(val===1?false:true)});
        $('#endTime').datebox({readonly:(val===1?false:true)});
    }
}

function btn_helplA() {
    window.open("http://172.29.92.5/showaHandbook#/sub/priority/")
}

function Priorities_addB(val) {
    if ($("#mainid").textbox('getValue')>0){}else{
        $.messager.show({title:'提示', msg:'先保存当前事项后再执行本操作！'});
        return;
    }
    if (val===0){
        //驳回
        $('#op1emarkR01').textbox({readonly:false});
        $('#op1emarkR02').textbox({readonly:false});
        $('#op2emarkR01').textbox({readonly:true});
        $('#op2emarkR02').textbox({readonly:true});

    }else if(val===1){
        //取消驳回
        $('#op1emarkR01').textbox({readonly:true});
        $('#op1emarkR02').textbox({readonly:true});
        $('#op2emarkR01').textbox({readonly:false});
        $('#op2emarkR02').textbox({readonly:false});

    }

    let load= {
        "op1emarkR01": "",
        "op1emarkR02": "",
        "detailid01": 0,
        "detailid02": 0,
        "op2emarkR01": '',
        "op2emarkR02": "",
        "detailid03": 0,
        "detailid04": 0,
        'op1Time01':'',
        'op1Time02':'',
        'op2Time01':'',
        'op2Time02':'',
        "id": $("#mainid").textbox('getValue')
    };

    $.ajax({
        url: strLin + "priorityDetail/selectByParentId/" + $("#mainid").textbox('getValue'),
        type: 'POST',
        dataType: 'json',
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            console.log(cdata);
            let data=cdata.data;
            if (data.length>0){
              for (let i=0;i<data.length;i++){
                  if (data[i].category==='驳回一次'){
                      load.detailid01=data[i].id;
                      load.op1emarkR01=data[i].op1Remark;
                      load.op2emarkR01=data[i].op2Remark;
                      load.op1Time01=data[i].op1Time;
                      load.op1Time02=data[i].op2Time;
                  }
                  if (data[i].category==='驳回二次'){
                      load.detailid02=data[i].id;
                      load.op1emarkR02=data[i].op1Remark;
                      load.op2emarkR02=data[i].op2Remark;
                      load.op2Time01=data[i].op1Time;
                      load.op2Time02=data[i].op2Time;
                  }
              }
            }
            $('#fff').form('load',load);
        }
    });

    $('#Priorities_winB').window('open');



}

function btn_saveB() {
    var formData = {}; // 创建一个空对象来存放数据

    // 选择所有表单中的输入字段
    $('#fff input').each(function() {
        var fieldName = $(this).attr('name'); // 获取字段名
        var fieldValue = $(this).val(); // 获取字段值
        formData[fieldName] = fieldValue; // 将数据添加到对象
    });

    let url;
    if (formData.id>0){
        url=strLin + 'priorityDetail/multiSave'
    }else{
        $.messager.show({title:'提示', msg:'无效事件,先保存有效优先事项！'});
        return;
    }

    console.log('优先事项驳回原因的数据是：', formData);
    let strData=[], obj01={},obj02={};
    let op1Time01='',op1Time02='',op2Time01='',op2Time02='';
    if (isNull(formData.op1Time01,0)!==0){op1Time01=formData.op1Time01}else{if (isNull(formData.op1emarkR01,0)!==0){op1Time01=formatNow()}}
    if (isNull(formData.op1Time02,0)!==0){op1Time02=formData.op1Time02}else{if (isNull(formData.op2emarkR01,0)!==0){op1Time02=formatNow()}}
    if (isNull(formData.op2Time01,0)!==0){op2Time01=formData.op2Time01}else{if (isNull(formData.op1emarkR02,0)!==0){op2Time01=formatNow()}}
    if (isNull(formData.op2Time02,0)!==0){op2Time02=formData.op2Time02}else{if (isNull(formData.op2emarkR02,0)!==0){op2Time02=formatNow()}}

    obj01={'id':formData.detailid01,'parentId':formData.id,'category':'驳回一次',
        'op1Remark':formData.op1emarkR01,'op1Time':isNull(op1Time01,0)===0?null:op1Time01,
        'op2Remark':formData.op2emarkR01,'op2Time':isNull(op1Time02,0)===0?null:op1Time02};
    obj02={'id':formData.detailid02,'parentId':formData.id,'category':'驳回二次',
        'op1Remark':formData.op1emarkR02,'op1Time':isNull(op2Time01,0)===0?null:op2Time01 ,
        'op2Remark':formData.op2emarkR02,'op2Time':isNull(op2Time02,0)===0?null:op2Time02 };
    strData.push(obj01);
    strData.push(obj02);

    console.log(strData);

    $.ajax({
        headers: {"usersid":Strusersid},
        url: url,
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(strData),
        contentType: "application/json;charset=UTF-8",
        success: function (data) {
            if (data.code != 1){
                $.messager.show({title:'提示', msg:data.msg});
                return;
            }else{
                // btn_cancelA();
                // Priorities_Refresh();
                btn_cancelB();
                $.messager.show({title:'提示', msg:'保存成功！！！'});
            }

        }
    });


}

function Priorities_Refresh() {
    let strSQL;
    if (getSelectedIndex01()===0){
        strSQL=['usp_getpriority_main',1];
    }else if(getSelectedIndex01()===1) {
        strSQL=['usp_getpriority_main', 0];
    }else if(getSelectedIndex01()===2){
        strSQL=['usp_getpriority_main',2];
    }
    $.ajax({
        url: strLin + "customSqlAccount/callProc",
        type: 'post',
        data: JSON.stringify(strSQL),
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            let  data=cdata.data;
            // console.log(data);
            if (getSelectedIndex01()===0){
                $('#PrioritiesGrid').datagrid('clearSelections');
                $('#PrioritiesGrid').datagrid('loadData', data);
            }else if(getSelectedIndex01()===1) {
                $('#PrioritiesGrid01').datagrid('clearSelections');
                $('#PrioritiesGrid01').datagrid('loadData', data);
            }else if(getSelectedIndex01()===2){
                $('#PrioritiesGridAll').datagrid('clearSelections');
                $('#PrioritiesGridAll').datagrid('loadData', data);
            }
        }
    });
}

function setPrioritiesGrid() {
    $('#PrioritiesGrid').datagrid({
        data: [],
        striped: true,
        autoSave: false,
        sortable: true,
        fit:true,
        ctrlSelect:false,
        rownumbers:true,
        remoteSort: false,
        singleSelect: true,
        showFooter: true,
        idField: 'iid',
        columns:[[
            {field:'id',title:'主键',width:100,hidden:true},
            {field:'sponsor',title:'提出者',width:100,align:'center',sortable:true},
            {field:'departmentSid',title:'提出部门',width:100,align:'center',sortable:true},
            {field:'billDate',title:'提出日期',width:100,align:'center',sortable:true},
            {field:'startTime',title:'预计开始日',width:120,align:'center',sortable:true},
            {field:'endTime',title:'预计结束日',width:120,align:'center',sortable:true},
            {field:'level',title:'紧急程度',width:100,align:'center',sortable:true},
            {field:'category',title:'项目分类',width:100,align:'center',sortable:true},
            {field:'content',title:'内容说明',width:150,align:'center',sortable:true},
            {field:'deadLine',title:'希望纳期',width:100,align:'center',sortable:true},
            {field:'principalDepartment',title:'担当部门',width:100,align:'center',sortable:true},
            {field:'principal',title:'担当者编号',width:150,align:'center',hidden:true},
            {field:'sname',title:'担当者',width:100,align:'center',sortable:true},
            {field:'assistDepartment',title:'协助部门',width:100,align:'center',sortable:true},
            {field:'solution',title:'处理方案',width:200,align:'center',sortable:true},
            {field:'progress01',title:'项目进展状态',width:120,align:'center',sortable:true},
            {field:'result',title:'项目结束验收',width:120,align:'center',sortable:true},
            {field:'intervalTime',title:'提醒间隔(H)',width:100,align:'center',sortable:true,hidden:true},
            {field:'notiTime',title:'提醒日期',width:200,align:'center',sortable:true},
            {field:'progress02',title:'临近逾期天数',width:100,hidden:true},
            {field:'op1Remark',title:'驳回原因',width:200,align:'center',sortable:true},
            {field:'op2Remark',title:'取消驳回原因',width:200,align:'center',sortable:true},

            {field:'postponeDeadline',title:'延期日期',width:100,align:'center',sortable:true},
            {field:'postponeRemark',title:'延期原因',width:200,align:'center',sortable:true},
            {field:'postponeAuditFlag',title:'审核',width:60,align:'center',sortable:true,formatter: function(value, row, index) {
                    // 格式化日期，假设value是一个包含日期的字符串
                    let formattedDate='';
                    if (Number(value)===1){formattedDate='通过'}else if(Number(value)===2){formattedDate='不通过'}
                    return formattedDate;
                }},
            {field:'postponeAuditRemark',title:'审核备注',width:200,align:'center',sortable:true},

        ]],
        onDblClickRow: function (Index,row) {//鼠标双击事件
            Priorities_add(row);
        },
        rowStyler: function(index, row) {
            if (row.result==='验收合格' ) {
                // 如果 statue 大于 0，将字体颜色设置为红色
                return 'color: #00AA00;';
            }
            if (row.progress01==='已逾期' ) {
                // 如果 statue 大于 0，将字体颜色设置为红色
                return 'color: red;';
            }
            if (row.progress02===1 || row.progress02===0) {
                // 如果 statue 大于 0，将字体颜色设置为红色
                return 'color: darkorange;';
            }
            // 默认样式
            return '';
        }
    });
}

function setPrioritiesGrid01() {
    $('#PrioritiesGrid01').datagrid({
        data: [],
        striped: true,
        autoSave: false,
        sortable: true,
        fit:true,
        ctrlSelect:true,
        rownumbers:true,
        remoteSort: false,
        singleSelect: false,
        showFooter: true,
        idField: 'iid',
        columns:[[
            {field:'id  ',title:'主键',width:100,hidden:true},
            {field:'createUser',title:'提出者',width:100,align:'center',sortable:true},
            {field:'departmentSid',title:'提出部门',width:100,align:'center',sortable:true},
            {field:'billDate',title:'提出日期',width:100,align:'center',sortable:true},
            {field:'level',title:'紧急程度',width:100,align:'center',sortable:true},
            {field:'category',title:'项目分类',width:100,align:'center',sortable:true},
            {field:'content',title:'内容说明',width:150,align:'center',sortable:true},
            {field:'deadLine',title:'希望纳期',width:100,align:'center',sortable:true},
            {field:'principalDepartment',title:'担当部门',width:100,align:'center',sortable:true},
            {field:'principal',title:'担当者编号',width:150,align:'center',hidden:true},
            {field:'sname',title:'担当者',width:100,align:'center',sortable:true},
            {field:'assistDepartment',title:'协助部门',width:100,align:'center',sortable:true},
            {field:'solution',title:'处理方案',width:200,align:'center',sortable:true},
            {field:'startTime',title:'预计开始日',width:120,align:'center',sortable:true},
            {field:'endTime',title:'预计结束日',width:120,align:'center',sortable:true},
            {field:'progress01',title:'项目进展状态',width:120,align:'center',sortable:true},
            {field:'result',title:'项目结束验收',width:120,align:'center',sortable:true},
            {field:'intervalTime',title:'提醒间隔(H)',width:100,align:'center',sortable:true,hidden:true},
            {field:'notiTime',title:'提醒日期',width:200,align:'center',sortable:true},
            {field:'op1Remark',title:'驳回原因',width:200,align:'center',sortable:true},
            {field:'op2Remark',title:'取消驳回原因',width:200,align:'center',sortable:true},

            {field:'postponeDeadline',title:'延期日期',width:100,align:'center',sortable:true},
            {field:'postponeRemark',title:'延期原因',width:200,align:'center',sortable:true},
            {field:'postponeAuditFlag',title:'审核',width:60,align:'center',sortable:true,formatter: function(value, row, index) {
                    // 格式化日期，假设value是一个包含日期的字符串
                    let formattedDate='';
                    if (Number(value)===1){formattedDate='通过'}else if(Number(value)===2){formattedDate='不通过'}
                    return formattedDate;
                }},
            {field:'postponeAuditRemark',title:'审核备注',width:200,align:'center',sortable:true},

            {field:'create_user',title:'关闭者',width:80,align:'center',sortable:true},
            {field:'create_time',title:'关闭时间',width:200,align:'center',sortable:true},

        ]],
        onDblClickRow: function (Index,row) {//鼠标双击事件
            Priorities_add(row);
        }
    });
}

function setPrioritiesGridAll() {
    $('#PrioritiesGridAll').datagrid({
        data: [],
        striped: true,
        autoSave: false,
        sortable: true,
        fit:true,
        ctrlSelect:true,
        rownumbers:true,
        remoteSort: false,
        singleSelect: false,
        showFooter: true,
        idField: 'iid',
        columns:[[
            {field:'id  ',title:'主键',width:100,hidden:true},
            {field:'state',title:'类型',width:80,align:'center',sortable:true},
            {field:'sponsor',title:'提出者',width:100,align:'center',sortable:true},
            {field:'departmentSid',title:'提出部门',width:100,align:'center',sortable:true},
            {field:'billDate',title:'提出日期',width:100,align:'center',sortable:true},
            {field:'level',title:'紧急程度',width:100,align:'center',sortable:true},
            {field:'category',title:'项目分类',width:100,align:'center',sortable:true},
            {field:'content',title:'内容说明',width:150,align:'center',sortable:true},
            {field:'deadLine',title:'希望纳期',width:100,align:'center',sortable:true},
            {field:'principalDepartment',title:'担当部门',width:100,align:'center',sortable:true},
            {field:'principal',title:'担当者编号',width:150,align:'center',hidden:true},
            {field:'sname',title:'担当者',width:100,align:'center',sortable:true},
            {field:'assistDepartment',title:'协助部门',width:100,align:'center',sortable:true},
            {field:'solution',title:'处理方案',width:200,align:'center',sortable:true},
            {field:'startTime',title:'预计开始日',width:120,align:'center',sortable:true},
            {field:'endTime',title:'预计结束日',width:120,align:'center',sortable:true},
            {field:'progress01',title:'项目进展状态',width:120,align:'center',sortable:true},
            {field:'result',title:'项目结束验收',width:120,align:'center',sortable:true},
            {field:'intervalTime',title:'提醒间隔(H)',width:100,align:'center',sortable:true,hidden:true},
            {field:'notiTime',title:'提醒日期',width:200,align:'center',sortable:true},
            {field:'progress02',title:'临近逾期天数',width:100,hidden:true},
            {field:'op1Remark',title:'驳回原因',width:200,align:'center',sortable:true},
            {field:'op2Remark',title:'取消驳回原因',width:200,align:'center',sortable:true},

            {field:'postponeDeadline',title:'延期日期',width:100,align:'center',sortable:true},
            {field:'postponeRemark',title:'延期原因',width:200,align:'center',sortable:true},
            {field:'postponeAuditFlag',title:'审核',width:60,align:'center',sortable:true,formatter: function(value, row, index) {
                    // 格式化日期，假设value是一个包含日期的字符串
                    let formattedDate='';
                    if (Number(value)===1){formattedDate='通过'}else if(Number(value)===2){formattedDate='不通过'}
                    return formattedDate;
                }},
            {field:'postponeAuditRemark',title:'审核备注',width:200,align:'center',sortable:true},

        ]],
        onDblClickRow: function (Index,row) {//鼠标双击事件
            Priorities_add(row);
        },
        rowStyler: function(index, row) {
            if (row.state==='已关闭' ) {
                // 如果 statue 大于 0，将字体颜色设置为红色
                return '';
            }
            if (row.progress01==='已逾期' ) {
                // 如果 statue 大于 0，将字体颜色设置为红色
                return 'color: red;';
            }
            if (row.progress02===1 ) {
                // 如果 statue 大于 0，将字体颜色设置为红色
                return 'color: darkorange;';
            }
            if (row.result==='验收合格' ) {
                // 如果 statue 大于 0，将字体颜色设置为红色
                return 'color: #00AA00;';
            }
            // 默认样式
            return '';
        }
    });
}


//设置延期 、审核延期
function Priorities_addC(val) {
// 获取datagrid中选中的行数据
    var selectedRows = $('#PrioritiesGrid').datagrid('getSelected');

// 打印选中行数据
//     console.log(selectedRows);

    if (selectedRows){
        if (val===0){
            //延期申请
            $('#postponeDeadline').datebox({readonly:false});
            $('#postponeRemark').textbox({readonly:false});
            $('#postponeAuditFlag').combobox({readonly:true,required:false});
            $('#postponeAuditRemark').textbox({readonly:true});

        }else if(val===1){
            //延期审核
            $('#postponeDeadline').datebox({readonly:true});
            $('#postponeRemark').textbox({readonly:true});
            $('#postponeAuditFlag').combobox({readonly:false,required:true});
            $('#postponeAuditRemark').textbox({readonly:false});
        }

        let load= {
            "postponeDeadline": selectedRows.postponeDeadline,
            "postponeRemark": selectedRows.postponeRemark,
            "postponeAuditFlag": selectedRows.postponeAuditFlag>0?selectedRows.postponeAuditFlag:'',
            "postponeAuditRemark":selectedRows.postponeAuditRemark,
            "id": selectedRows.id,
            "billtype":val
        };

        $('#ffff').form('load',load);
        $('#Priorities_winC').window('open');
    }else{
        $.messager.show({title:'提示', msg:'未选择数据！'});
    }

}

function btn_saveC() {
    var formData = {}; // 创建一个空对象来存放数据

    // 选择所有表单中的输入字段
    $('#ffff input').each(function() {
        var fieldName = $(this).attr('name'); // 获取字段名
        var fieldValue = $(this).val(); // 获取字段值
        formData[fieldName] = fieldValue; // 将数据添加到对象
    });

    let url,strData={};
    if (Number(formData.billtype)===0){
        url=strLin + 'priorityMain/setPostpone';
        strData= {"id":formData.id,"postponeRemark":formData.postponeRemark,"postponeDeadline":formData.postponeDeadline};
    }else if (Number(formData.billtype)===1){
        url=strLin + 'priorityMain/auditPostpone';
        strData= {"id":formData.id,"postponeAuditFlag":Number(formData.postponeAuditFlag),"postponeAuditRemark":formData.postponeAuditRemark};
    }

    $.ajax({
        headers: {"usersid":Strusersid},
        url: url,
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(strData),
        contentType: "application/json;charset=UTF-8",
        success: function (data) {
            if (data.code != 1){
                $.messager.show({title:'提示', msg:data.msg});
                return;
            }else{
                btn_cancelC();
                Priorities_Refresh();
                $.messager.show({title:'提示', msg:'保存成功！！！'});
            }
        }
    });

}

function btn_cancelC() {
    $('#Priorities_winC').window('close');
}